/**
 * 
 */
package br.com.sistransporte.transitevo.tabelahorario.model;

import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import br.com.sistransporte.transite.utilidades.Constantes;
import br.com.sistransporte.transitevo.diasemana.model.DiaSemanaVO;
import br.com.sistransporte.transitevo.evento.model.EventoVO;
import br.com.sistransporte.transitevo.horario.model.HorarioVO;
import br.com.src.masterpersistence.abstractpersistence.AbstractVO;
import br.com.src.masterpersistence.annotations.CronosFilter;

/**
 * Classe que representa
 *
 *
 * @author Nelson Luis da Silva Junior <nelson.jr13@hotmail.com>
 * @since 17 de Set de 2013 18:02:07
 * @version 1.0
 */
@Entity
@Table(name="tabela_horario", schema=Constantes.SCHEMA)
public class TabelaHorarioVO extends AbstractVO{
	
	@CronosFilter
	@ManyToOne(fetch=FetchType.EAGER)
	@JoinColumn(name="id_dia_semana", nullable=false)
	private DiaSemanaVO diaSemana;
	
	@CronosFilter
	@ManyToMany( fetch = FetchType.EAGER, cascade = {CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH} )
	@JoinTable( name = "horarios_tabela_horario", joinColumns = @JoinColumn( name = "id_tabela_horario" ), inverseJoinColumns = @JoinColumn( name = "id_horario" ), schema = Constantes.SCHEMA )
	private Set< HorarioVO > listaHorarios;
	
	@CronosFilter
	@ManyToOne( fetch = FetchType.EAGER )
	@JoinColumn(name="id_evento", nullable=true)
	private EventoVO evento;
	
	public TabelaHorarioVO(){}
	
	public TabelaHorarioVO( Integer id, DiaSemanaVO diaSemana, Set< HorarioVO > listaHorarios, EventoVO evento ){
	    super( id );
	    setDiaSemana( diaSemana );
	    setListaHorarios( listaHorarios );
	    setEvento( evento );
    }
	
	public DiaSemanaVO getDiaSemana() {
    	return diaSemana;
    }

	public void setDiaSemana( DiaSemanaVO diaSemana ) {
    	this.diaSemana = diaSemana;
    }

	public Set< HorarioVO > getListaHorarios() {
    	return listaHorarios;
    }

	public void setListaHorarios( Set< HorarioVO > listaHorarios ) {
    	this.listaHorarios = listaHorarios;
    }
	
	public EventoVO getEvento() {
    	return evento;
    }

	public void setEvento( EventoVO evento ) {
    	this.evento = evento;
    }

	@Override
    public String toString() {
	    return "TabelaHorarioVO [diaSemana=" + diaSemana + ", listaHorarios=" + listaHorarios + ", evento=" + evento + "]";
    }

	@Override
    public int hashCode() {
	    final int prime = 31;
	    int result = 1;
	    result = prime * result + ( ( diaSemana == null ) ? 0 : diaSemana.hashCode() );
	    result = prime * result + ( ( evento == null ) ? 0 : evento.hashCode() );
	    return result;
    }

	@Override
    public boolean equals( Object obj ) {
	    if ( this == obj )
		    return true;
	    if ( obj == null )
		    return false;
	    if ( getClass() != obj.getClass() )
		    return false;
	    TabelaHorarioVO other = (TabelaHorarioVO) obj;
	    if ( diaSemana == null ) {
		    if ( other.diaSemana != null )
			    return false;
	    } else if ( !diaSemana.equals( other.diaSemana ) )
		    return false;
	    if ( evento == null ) {
		    if ( other.evento != null )
			    return false;
	    } else if ( !evento.equals( other.evento ) )
		    return false;
	    return true;
    }
}
